<template>
	<view style="padding-top: 20upx;">
		<view class="webkit list">
			<view class="title">支付宝收款姓名</view>
			<input type="text" v-model="alipay_username" class="flex" />
		</view>
		<view class="webkit list">
			<view class="title">支付宝账号</view>
			<input type="text" v-model="alipay_id" class="flex" />
		</view>
		<view style="padding: 0 24upx;">
			<button type="primary" style="background-color: #EB2E15; margin-top: 20upx;" @click="submit" :loading="loading">提交</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				res:[],
				openid:'',
				id:0,
				loading: false,
				alipay_id: '',
				alipay_username: '',
			};
		},
		onLoad:function(e){
			if (e.id) {
				this.id = e.id
			}
			uni.showLoading()
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					this.setAjax()
				},
				fail: () => {
					uni.reLaunch({
						url: '/pagesA/login/login'
					})
				}
			});
		},
		methods:{
			setAjax(){
				uni.request({
					url: 'http://mall.sytesco.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.alipay_info&app=1',
					method: 'POST',
					data: {
						openid:this.openid,
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					success: res => {
						if (res.data.alipay_id != null) {
							this.alipay_id = res.data.alipay_id
						}
						if (res.data.alipay_username != null) {
							this.alipay_username = res.data.alipay_username
						}
						uni.hideLoading()
					},
					fail: () => {},
					complete: () => {}
				});
				
			},
			submit(){
				if (this.alipay_id=="" || this.alipay_username=="") {
					uni.showToast({
						title: '有填入的信息为空'
					})
					return
				} else {
					uni.request({
						url: 'http://mall.sytesco.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.alipay_sub&app=1',
						method: 'POST',
						data: {
							openid:this.openid,
							alipay_id:this.alipay_id,
							alipay_username:this.alipay_username,
						},
						header: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},
						success: res => {
							console.log(res)
							// uni.showToast({
							// 	title: res.data.result.message,
							// 	icon: "none"
							// });
							if (this.id != 0) {
								uni.redirectTo({
									url: '/pages/order/pay/pay?id=' + this.id
								})
							} else {
								uni.navigateBack()
							}
							// setTimeout(() => {
							// 	if(res.data.status==1){
							// 		uni.navigateTo({
							// 			url: '../../../pages/login/login'
							// 		});
							// 	}
							// }, 1500)
						},
						fail: () => {},
						complete: () => {}
					});
				}
			},
			jump(e){
				uni.navigateTo({
					url: e.currentTarget.dataset.src
				});
			},
		}
	}
</script>

<style>.list{padding:26upx 20upx;background:#fff;position:relative;}.list:last-child:after{display:none;}.list:after{content:" ";position:absolute;left:20upx;right:20upx;bottom:-2upx;height:2upx;border-top:2upx solid #ebebeb;color:#D9D9D9;-webkit-transform-origin:0 0;-ms-transform-origin:0 0;transform-origin:0 0;-webkit-transform:scaleY(0.5);-ms-transform:scaleY(0.5);transform:scaleY(0.5);}.list .title{width:250upx;line-height:50upx;color:#666;}.list .flex{line-height:50upx;color:#666;padding-left:24upx;}.inputright{width:200upx;height:52upx;}button.inputright{line-height:48upx;font-size:24upx;background:transparent;border:2upx solid #333;}</style>
